package com.ohuang.jiaxiaotong.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.ohuang.jiaxiaotong.R;
import com.ohuang.jiaxiaotong.Util.Ohuang;

import java.util.Objects;

public class WebActivity extends AppCompatActivity {
    private String url,title;
    private WebView webView;
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);

        Intent intent=getIntent();
        url=intent.getStringExtra("url");
        title=intent.getStringExtra("title");
          if (getSupportActionBar()!=null){
              getSupportActionBar().hide();
          }
        Ohuang.changeStatusBarTextImgColor(this, true);



        webView=findViewById(R.id.web_webView);
        textView=findViewById(R.id.web_text_titles);
        textView.setText(title);
        initWebView();
    }

    private void initWebView() {
        WebSettings settings=webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setBuiltInZoomControls(true);

        webView.requestFocus();
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

        //设置点击链接在当前的webview显示
//        webView.setWebViewClient(new WebViewClient(){
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//
//                view.loadUrl(url);
//                return false;
//            }
//        });

        webView.loadUrl(url);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK&&webView.canGoBack()){
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


    public void webBackClick(View view) {
        finish();
    }

    public void shareClick(View view) {
        Intent intent=new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,url);
//        startActivity(intent);
        //指定选择器
        startActivity(Intent.createChooser(intent,"分享到"));
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
